/**********************************************************************************************************************
 *
 * Project:    mGameEngine
 * File:       positionallight.cpp
 * Author:     karooolek
 * Created on: 2009-03-27
 *
 **********************************************************************************************************************/

#include "positionallight.h"

namespace mGameEngine
{
namespace Graphics
{

PositionalLight::PositionalLight() :
    AmbientLight(),
    _position(),
    _diffuse(1.0f, 1.0f, 1.0f), _specular(1.0f, 1.0f, 1.0f),
    _constantAttenuation(1.0f), _linearAttenuation(0.0f),
    _quadraticAttenuation(0.0f)
{
}

PositionalLight::PositionalLight(const Color &ambient, const Color &diffuse,
        const Color &specular,
        float constantAttenuation, float linearAttenuation,
        float quadraticAttenuation,
        const Vector3 &position) :
    AmbientLight(ambient),
    _position(position),
    _diffuse(diffuse), _specular(specular),
    _constantAttenuation(constantAttenuation),
    _linearAttenuation(linearAttenuation),
    _quadraticAttenuation(quadraticAttenuation)
{
}

PositionalLight::~PositionalLight()
{
}

void PositionalLight::set(uint l) const
{
    if(!_enabled)
    {
        return;
    }

    l += GL_LIGHT0;
    glLightfv(l, GL_AMBIENT, _ambient);
    glLightfv(l, GL_DIFFUSE, _diffuse);
    glLightfv(l, GL_SPECULAR, _specular);
    glLightf(l, GL_CONSTANT_ATTENUATION, _constantAttenuation);
    glLightf(l, GL_LINEAR_ATTENUATION, _linearAttenuation);
    glLightf(l, GL_QUADRATIC_ATTENUATION, _quadraticAttenuation);
    glLightfv(l, GL_POSITION, Vector4(_position));
//    glLightfv(l, GL_SPOT_DIRECTION, Vector4(1.0f, 0.0f, 0.0f));
    glLightf(l, GL_SPOT_CUTOFF, 0.0f);
    glLightf(l, GL_SPOT_EXPONENT, 0.0f);
}

}
}

